package com.kgc.app.controller;

import com.kgc.app.pojo.DevUser;
import com.kgc.app.service.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/dev/user")
public class DevUserController {

    @Autowired
    private DevUserService devUserService;

    @RequestMapping("/login")
    public String login(String devCode, String devPassword, Model model, HttpSession session){

        DevUser devUser = devUserService.loginDevUser(devCode, devPassword);

        if (null == devUser){
            model.addAttribute("error","用户名或密码错误");
            return "forward:/jsp/devlogin.jsp";
        }

        session.setAttribute("devUser",devUser);

        return "/developer/main";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("devSuer");
        return "redirect:/jsp/devlogin.jsp";
    }

}
